//
//  PMDemo.h
//  PezMonkeyTest
//
//  Created by Spence DiNicolantonio on 11/3/09.
//  Copyright 2009 Necrosoft. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import <GLUT/GLUT.h>
#import "PezMonkey.h"


#pragma mark Types / Constants

typedef struct _PMDemoOptions {
	BOOL drawSpacialHash;
	BOOL drawBoundingBoxes;
	BOOL drawBodyPoints;
	BOOL drawCollisions;
} PMDemoOptions;

static const PMDemoOptions PMDemoOptionsDefault = 
{
	NO,		// draw spacial hash visualization
	NO,		// draw bounding boxes
	YES,	// draw body (center of gravity) points
	NO,		// draw collisions
};

typedef struct _PMDemoDrawSettings {
	BOOL drawShapes;
	BOOL fillShapes;
	BOOL fillSensors;
	PMFloat bodyPointSize;
	PMFloat collisionPointSize;
	PMFloat lineWidth;
} PMDemoDrawSettings;

static const PMDemoDrawSettings PMDemoDrawSettingsDefault = 
{
	YES,	// draw shapes
	YES,	// fill shapes
	NO,		// fill sensor shapes
	3.0,	// body (center of gravity) point size
	3.5,	// collision point size
	1.5		// line width
};

static const PMLayerMask PMLayerMaskNotGrabbable = 0x0001;

#pragma mark -


@interface PMDemo : NSObject {
	PMSpace *space;
	
	// display toggles
	PMDemoOptions demoOptions;
	
	// arrow keys
	BOOL leftArrow;
	BOOL rightArrow;
	BOOL upArrow;
	BOOL downArrow;
	
	// mouse location
	PMVect mousePoint;
	
	// dictionary containing all message strings
	NSMutableDictionary *strings;
}

@property (nonatomic, retain) PMSpace *space;
@property (assign) PMDemoOptions demoOptions;
@property (assign) BOOL leftArrow;
@property (assign) BOOL rightArrow;
@property (assign) BOOL upArrow;
@property (assign) BOOL downArrow;
@property (assign) PMVect mousePoint;
@property (nonatomic, retain) NSMutableDictionary *strings;

#pragma mark -
#pragma mark Init
- (id)initWithDemoOptions:(PMDemoOptions)options;

#pragma mark -
#pragma mark Drawing
- (void)draw;
+ (void)drawShape:(PMShape *)shape withSettings:(PMDemoDrawSettings)options;
+ (void)drawCircleShape:(PMCircleShape *)circle fill:(BOOL)fill;
+ (void)drawSegmentShape:(PMSegmentShape *)segment fill:(BOOL)fill;
+ (void)drawPolygonShape:(PMPolygonShape *)polygon fill:(BOOL)fill;
+ (void)drawBoundingBox:(PMShape *)shape;
+ (void)drawConstraint:(PMConstraint *)constraint;
+ (void)drawSpatialHash:(cpSpaceHash *)hash;
+ (void)drawCollision:(PMCollision *)collision;
+ (void)drawSpring:(PMDampedSpring *)spring;
+ (void)drawString:(NSString *)string atPoint:(NSPoint)point;
+ (void)setGLColorFromPointer:(void *)ptr;



#pragma mark -
#pragma mark Abstract Methods
- (void)start;
- (PMDemoDrawSettings)drawSettings;
- (void)update:(NSTimeInterval)deltaT;
- (NSString *)demoName;

@end


#pragma mark -
#pragma mark Functions

// Copied from cpSpaceHash.c
static inline cpHashValue hashFunc(cpHashValue x, cpHashValue y, cpHashValue n) {
	return (x*1640531513ul ^ y*2654435789ul) % n;
}
